/**
 * 
 */
package com.snapp.web.agents;

import java.util.HashMap;

import org.apache.log4j.Logger;

import com.snapp.util.object.model.ObjectModel;

/**
 * @author Kile
 *
 */
public class TemplateAgent extends SNAppAgent {
	private Logger logger = Logger.getLogger(TemplateAgent.class);
	
	public ObjectModel saveTemplate(HashMap<String,Object> params) {
		// copy parameters
		HashMap<String, Object> pc = new HashMap<String, Object>();
		pc.putAll(params);
		
		ObjectModel file = null;
		try {
			if (pc.containsKey("fileid")){
				pc.put("id", pc.get("fileid"));
			}
			
			file = save("SNAPP_FILE", pc);
		} catch (Exception e1) {
			logger.error("Error saving file record", e1);
			return null;
		}
		
		params.put("fileid", file.getBean().getPropertyString(file.getIdName()));
		
		ObjectModel template = null;
		try {
			template = save("SNAPP_TEMPLATE", params);
		} catch (Exception e) {
			logger.error("Error saving template record", e);
			return null;
		}
		
		return template;
	}
}
